package cn.oa;

import cn.oa.dao.EmployeeDao;
import cn.oa.entity.Department;
import cn.oa.entity.Employee;
import cn.oa.service.DepartmentService;
import cn.oa.service.EmployeeService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.List;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/3/29 11:11
 **/
public class Test {
//	SqlSession sqlSession;
//
//	@Before
//	public void before(){
//		InputStream is = null;
//		try {
//			is = Resources.getResourceAsStream("mybatis-config.xml");
//			SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
//			sqlSession =  factory.openSession();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
//
//	@After
//	public void after(){
//		if (sqlSession!=null){
//			sqlSession.close();
//		}
//	}
//
//	@org.junit.Test
//	public void testEmployee(){
//		EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
//		try {
//			Employee tmp =  employeeDao.findEmployee("1000890901", "123456");
//		} catch (SQLException throwables) {
//			throwables.printStackTrace();
//		}
//	}
	@org.junit.Test
	public void getasd() throws SQLException {
//		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext01.xml");
//		DepartmentService dao= (DepartmentService) context.getBean("departmentService");
//		List<Department> list=dao.getAllDepartments();
//		System.out.println(list.size());

		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext01.xml");
		EmployeeService dao= (EmployeeService) context.getBean("employeeService");
		Employee list=dao.findEmployee("1000890901", "1234567");
		System.out.println(list);

//		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext01.xml");
//		DepartmentService dao=context.getBean("departmentService",DepartmentService.class);
//		List<Department> ret=dao.getAllDepartments();
//		for (Department tmp:ret){
//			System.out.println(tmp.getId());
//		}
	}
}
